package cc.lj.internal.merchant.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.merchant.domain.contract.model.vo.PropertyRelationDO;
import cc.lj.internal.merchant.domain.contract.repository.IPropertyRelationRepository;
import cc.lj.internal.merchant.infrastructure.dao.IPropertyRelationMapper;
import cc.lj.internal.merchant.infrastructure.dao.IPropertyResourcesMapper;
import cc.lj.internal.merchant.infrastructure.exception.MerchantExceptionEnum;
import cc.lj.internal.merchant.infrastructure.po.PropertyRelationPO;
import cc.lj.internal.merchant.infrastructure.util.TransitionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 物业资源分类表　Mysql仓储实现
 * @author liangxifeng
 * @date 2021-12-24
 */
@Slf4j
@Service(value = "propertyRelationMysqlRespository")
public class PropertyRelationMysqlRespository implements IPropertyRelationRepository, BasePageHelper<PropertyRelationPO> {
    @Resource
    private IPropertyRelationMapper relationMapper;

    @Override
    public List<PropertyRelationPO> getList(PropertyRelationPO propertyRelationPO) {
        return list(propertyRelationPO);
    }

    @Override
    public List<PropertyRelationPO> list(PropertyRelationPO param) {
        QueryWrapper<PropertyRelationPO> wrapper = new QueryWrapper<>(param);
        List<PropertyRelationPO> entitys = relationMapper.selectList(wrapper);
        if(entitys == null)
        {
            throw new ServiceException(MerchantExceptionEnum.PROPERTY_RELATION_LIST_NULL);
        }
        return entitys;
        //db_ljlj数据库的默认编码是latin1，数据是gbk编码方式的，因此需要转码
        //return entitys.stream().map(t -> transitionUtil.tst(t)).collect(Collectors.toList());
    }
}
